module openglutils.GLVertexBuffer;

import openglutils.GL;
import openglutils.GLObject;

public class GLVertexBuffer : GLObject
{
	public void enable()
	{
		glEnableClientState(GL_VERTEX_ARRAY);
	}
	
	public void disable()
	{
		glDisableClientState(GL_VERTEX_ARRAY);
	}
	
	private void _bind(GLenum T)()
	{
		glBindBuffer(T, getId());
	}
	
	public alias _bind!(GL_ARRAY_BUFFER) bindArrayBuffer;
	
	public alias _bind!(GL_ELEMENT_ARRAY_BUFFER) bindElementArrayBuffer;
	
	private void _setBufferData(GLenum T)(GLvoid* data, GLsizeiptr size, GLenum usage)
	{
		glBufferData(T, size, data, usage);
	}
	
	public alias _setBufferData!(GL_ARRAY_BUFFER) setArrayBufferData;
	
	public alias _setBufferData!(GL_ELEMENT_ARRAY_BUFFER) setElementArrayBufferData;
	
	protected override void destroy()
	{
		GLuint id = getId();
		glDeleteBuffers(1, &id);
	}
	
	protected override GLuint generateID()
	{
		GLuint id;
		glGenBuffers(1, &id);
		return id;
	}
}

